<template>
  <div class="panel-2 card-common-cls" :class="{'mask-cls': maskable}" @click="click2Drag">
    <img :src="item.pic_url || `${env.publicPath}images/default-img.png`" :width="width" :height="height" alt="">
  </div>
</template>

<script>
  export default {
    data() {
      return {
        width: 0,
      }
    },
    props: {
      item: Object,
      maskable: {
        type: Boolean,
        default: true,
      },
    },
    computed: {
      height() {
        const _originalH = this.item && this.item.height && !isNaN(parseInt(this.item.height)) ? parseInt(this.item.height) : 0;
        const _originalW = this.item && this.item.width && !isNaN(parseInt(this.item.width)) ? parseInt(this.item.width) : this.width;
        let _newH = _originalH * this.width / _originalW;
        return _newH;
      },
    },
    mounted() {
      const _box = document.querySelector('.panel-2');
      this.width = _box.style.width || _box.clientWidth || _box.offsetWidth || _box.scrollWidth || 250;
    },
    methods: {
      click2Drag() {
        // console.log(e);
      },
    },
  }
</script>

<style lang="scss" scoped>
  .mask-cls::before {
    position: absolute;
    content: '';
    width: 100%;
    height: 100%;
    z-index: 999;
  }

  .panel-2 {
    min-height: 50px;
  }
  .card-common-cls {
    position: relative;
    width: 100%;
    max-width: 375px;
    z-index: 0;

    img {
      display: block;
    }
  }
</style>
